<?php

namespace App;

use App\Model;

class Post extends Model
{
    //关联用户
    public function user ()
    {
        return $this -> belongsTo('App\User', 'user_id', 'id');
    }

    //评论
    public function comments ()
    {
        return $this -> hasMany('App\comment') -> orderBy('created_at', 'desc');
    }

    //用户关联赞
    public function zan ($user_id)
    {
        return $this -> hasOne(\App\Zan::class) -> where('user_id', $user_id);
    }

    //文章所有赞
    public function zans ()
    {
        return $this->hasMany(\App\Zan::class);
    }

}
